<template>
  <div class="page">
    <mine-video
      :show="show_video"
      @close="show_video = false"
      :video-url="info.video"
      :image-url="info.image"
    ></mine-video>
    <div class="banner">
      <img :src="info.image3" alt />
      <div class="mask"></div>
    </div>
    <i class="el-icon-video-play play" @click="show_video = true" v-if="info.video"></i>
    <el-carousel
      :autoplay="false"
      type="card"
      :height="item_height"
      class="important"
      arrow="never"
    >
      <el-carousel-item>
        <div class="item">
          <img :src="info.icon" alt />
          <!-- <span>{{ info.icon_title }}</span>
          <p>{{ info.icon_description }}</p>-->
          <span>{{ info.icon_title }}</span>
          <p>{{ info.icon_description }}</p>
          <div @click="buyYear" v-if="!$store.state.is_vip">购买会员</div>
          <div @click="buyYear" v-else>续费会员</div>
        </div>
      </el-carousel-item>
      <el-carousel-item>
        <div class="item">
          <img :src="info.icon2" alt />
          <span>{{ info.icon_title2 }}</span>
          <p>{{ info.icon_description2 }}</p>
          <div @click="changePage" v-if="is_learn">继续学习</div>
          <div @click="changePage" v-else>加入课程</div>
        </div>
      </el-carousel-item>
      <el-carousel-item>
        <div class="item">
          <img :src="info.icon3" alt />
          <span>{{ info.icon_title3 }}</span>
          <p>{{ info.icon_description3 }}</p>
          <div @click="buy" v-if="!is_pay">{{ info.price }}元 购买本系列课程</div>
          <div v-else @click="$store.state.mine_index = 5;$router.push('/mine/index')">查询购买记录</div>
          <!-- <div @click="download(info.file)" v-if="info.file">资料下载</div> -->
        </div>
      </el-carousel-item>
    </el-carousel>
    <!-- 课程组描述 -->
    <div class="introduce">
      <img :src="info.image4" alt />
      <div>
        <span>{{ info.number_title }}</span>
        <p>{{ info.description }}</p>
        <div>
          <div>
            <p>{{ info.number }}</p>
            <p>{{ info.number2 }}</p>
          </div>
          <div>
            <p>{{ info.number3 }}</p>
            <p>{{ info.number4 }}</p>
          </div>
          <div>
            <p>{{ info.number5 }}</p>
            <p>{{ info.number6 }}</p>
          </div>
        </div>
      </div>
    </div>
    <!-- 课程之外 -->
    <div
      class="point"
      @click="
        $router.push({
          path: '../active',
          query: {
            id: $route.query.id
          }
        })
      "
      v-if="other_list.length"
    >
      <img :src="info.image3" alt />
      <div>
        <div v-for="(item, index) in other_list" :key="index">
          <i class="el-icon-service"></i>
          <span>{{ item.name }}</span>
          <p v-if="item.description">{{ item.description }}</p>
        </div>
      </div>
    </div>
    <!-- 课程组目录 -->
    <el-collapse class="list" :accordion="true" v-if="lesson.length && is_pay">
      <el-collapse-item :name="index" v-for="(item, index) in lesson" :key="index">
        <template slot="title">
          <div class="title">
            <span>{{ index < 9 ? "0" + (index + 1) : index + 1 }}</span>
            <div>
              <span>{{ item.name }}</span>
              <p v-if="item.description">{{ item.description }}</p>
            </div>
          </div>
        </template>
        <div class="content">
          <div
            @click="
              $router.push({
                path: 'detail',
                query: {
                  id: item.id
                }
              })
            "
          >
            <i class="el-icon-caret-right"></i>
            <p>播放视频 视频总长度：{{item.study_time}}</p>
          </div>
          <div>
            <i class="el-icon-notebook-2"></i>
            <p>可学到的内容：{{item.study_content}}</p>
          </div>
          <div @click="download(item.file)" v-if="item.file">
            <i class="el-icon-document"></i>
            <p>资料下载</p>
          </div>
          <div>
            <img src="@/assets/vr.png" alt />
            <p>VR 播放</p>
          </div>
        </div>
      </el-collapse-item>
    </el-collapse>
    <div class="list" v-if="lesson.length && !is_pay">
      <div class="title" v-for="(item, index) in lesson" :key="index">
        <span>{{ index < 9 ? "0" + (index + 1) : index + 1 }}</span>
        <div>
          <span>{{ item.name }}</span>
          <p>{{ item.description }}</p>
        </div>
      </div>
    </div>
    <div class="mine-title">
      <p>Our Recommendation</p>
      <span>为你推荐的大师</span>
    </div>
    <teacher></teacher>
  </div>
</template>

<script>
import mineVideo from "@/components/dialog/video";
import teacher from "@/components/list/teacher";
export default {
  components: {
    teacher,
    mineVideo
  },
  data() {
    return {
      history_id: 0,
      show_video: false,
      info: {},
      is_pay: false,
      lesson: [],
      recommend: [],
      other_list: [],
      nav_list: [
        {
          name: "课程计划"
        },
        {
          name: "课程下载"
        }
      ],
      // year_price: 0,
      is_learn: 0,
      item_height: "3.3rem"
    };
  },
  beforeRouteUpdate(to, from, next) {
    let _this = this;
    _this.reload(to.query.id, next);
  },
  created() {
    let _this = this;
    _this.reload(_this.$route.query.id);
    if (document.body.clientWidth * 2 < 1000) {
      _this.item_height = "4rem";
    }
    // _this.$axios.get("site/vip").then(res => {
    //   _this.year_price = res.price;
    // });
  },
  methods: {
    changePage() {
      let _this = this;
      if (_this.$store.state.is_login) {
        _this.$router.push({
          path: "detail",
          query: {
            id: _this.history_id
          }
        });
      } else {
        _this.$store.state.show_login = true;
      }
    },
    reload(id, next) {
      let _this = this;
      _this.$axios.get("group/show/" + id).then(res => {
        console.log("test", res);
        _this.info = res.info;
        _this.is_pay = res.is_pay;
        _this.is_learn = res.is_learn;
        _this.history_id = res.history_id;
        _this.lesson = res.lesson;
        if (next) next();
      });
      _this.$axios
        .get("lesson/other", {
          params: {
            other_id: id
          }
        })
        .then(res => {
          _this.other_list = res.column;
        });
    },
    buyYear() {
      let _this = this;
      _this.$store.state.show_recharge = true;
      _this.$store.state.order_type = "vip";
      _this.$store.state.group_id = _this.info.id;
    },
    buy() {
      let _this = this;
      _this.$store.state.show_recharge = true;
      _this.$store.state.order_type = "lesson";
      _this.$store.state.group_id = _this.info.id;
      _this.$store.state.group_price = _this.info.price;
    },
    download(url) {
      window.open(url);
    }
  }
};
</script>

<style lang="less" scoped>
.banner {
  width: 100%;
  height: 6rem;
  position: absolute;
  top: 0;
  overflow: hidden;
  > img {
    width: 100%;
    height: 100%;
    border-radius: 0 0 50% 50%;
    position: absolute;
    object-fit: cover;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
  }
  .mask {
    width: 100%;
    height: 100%;
    position: absolute;
    border-radius: 0 0 50% 50%;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    box-shadow: 0 0 1rem 0.3rem black inset;
    overflow: hidden;
  }
}
.play {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  border-radius: 50%;
  transition: all 200ms;
  cursor: pointer;
  position: absolute;
  top: 3rem;
  transform: translateY(-50%);
}
.play:hover {
  font-size: 1rem;
}
.important {
  width: @width;
  margin-bottom: 0.6rem;
  margin-top: 6.3rem;
  @media only screen and (max-width: 500px),
    only screen and (max-device-width: 500px) {
    width: calc(100vw);
  }
  .item {
    width: calc(100% - 2rem);
    height: calc(100% - 0.3rem);
    margin: auto;
    margin-top: 0.3rem;
    box-shadow: 0 0 0.3rem 0.1rem rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    > img {
      width: 1rem;
      height: 1rem;
      box-sizing: border-box;
      padding: 0.2rem;
      background: @gold-color;
      border-radius: 50%;
      position: absolute;
      top: 0;
    }
    > span {
      font-size: @title-size;
      margin-top: 1rem;
      margin-bottom: 0.2rem;
    }
    > p {
      // width: 80%;
      text-align: center;
    }
    > div {
      padding: 0.1rem 0.3rem;
      margin-top: 0.2rem;
      border: 2px white solid;
      transition: 300ms;
      text-align: center;
    }
    > div:hover {
      background: white;
      color: black;
    }
  }
}
.introduce {
  width: @width;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  color: @black-color;
  position: relative;
  margin-bottom: 1rem;
  @media only screen and (max-width: 500px),
    only screen and (max-device-width: 500px) {
    width: calc(100vw - 0.6rem);
    flex-direction: column;
  }
  > img {
    width: 5rem;
    height: 5rem;
    object-fit: cover;
    mask-image: url("~@/assets/shape.png");
    mask-size: 5rem 5rem;
    @media only screen and (max-width: 500px),
      only screen and (max-device-width: 500px) {
      width: 100%;
      height: calc(100vw - 0.6rem);
      mask-size: 100% 100%;
    }
  }
  > div {
    width: calc(100% - 5.6rem);
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-sizing: border-box;
    color: white;
    padding: 0.2rem;
    @media only screen and (max-width: 500px),
      only screen and (max-device-width: 500px) {
      width: 100%;
      padding: 0;
      margin-top: 0.5rem;
    }
    > span {
      font-size: 0.3rem;
    }
    > p {
      overflow: hidden;
      font-size: 0.2rem;
      margin-top: 0.3rem;
      line-height: 0.3rem;
      word-break: break-all;
    }
    > div {
      width: 100%;
      display: flex;
      flex-direction: row;
      align-items: flex-end;
      justify-content: space-between;
      > div {
        display: flex;
        flex-direction: column;
        margin-top: 0.3rem;
        > span {
          font-size: 0.5rem;
        }
        > p {
          font-size: 0.18rem;
          margin-bottom: 0.2rem;
        }
      }
    }
  }
}
.point {
  width: @width;
  height: 4rem;
  position: relative;
  cursor: pointer;
  margin-bottom: 0.3rem;
  @media only screen and (max-width: 500px),
    only screen and (max-device-width: 500px) {
    width: calc(100vw - 0.6rem);
    height: auto;
  }
  > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
  }
  > div {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
    padding: 0.5rem 0.8rem;
    box-sizing: border-box;
    @media only screen and (max-width: 500px),
      only screen and (max-device-width: 500px) {
      height: auto;
      flex-direction: column;
      padding: 0;
    }
    > div {
      width: 3rem;
      background: white;
      color: @black-color;
      box-sizing: border-box;
      padding: 0.4rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      @media only screen and (max-width: 500px),
        only screen and (max-device-width: 500px) {
        width: 100%;
      }
      > i {
        font-size: 0.5rem;
      }
      > span {
        font-size: @title-size;
        margin-top: 0.1rem;
      }
      > p {
        font-size: @normal-size;
        color: @node-color;
        margin-top: 0.1rem;
        text-align: center;
      }
    }
    > div + div {
      margin-left: 0.3rem;
      @media only screen and (max-width: 500px),
        only screen and (max-device-width: 500px) {
        margin-left: 0;
        margin-top: 0.3rem;
      }
    }
  }
}
.list {
  width: @width;
  box-sizing: border-box;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  background: @dark-color;
  @media only screen and (max-width: 500px),
    only screen and (max-device-width: 500px) {
    width: calc(100vw - 0.6rem);
  }
  .title {
    width: 90%;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    font-size: @big-size;
    padding-top: 0.3rem;
    padding-bottom: 0.3rem;
    > span {
      width: 0.7rem;
      height: 0.7rem;
      font-size: 0.25rem;
      display: flex;
      align-items: center;
      justify-content: center;
      color: @gold-color;
      border: 3px @gold-color solid;
      border-radius: 0.05rem;
      box-sizing: border-box;
    }
    > div {
      width: calc(100% - 1rem);
      display: flex;
      flex-direction: column;
      justify-content: center;
      > span {
        font-size: @title-size;
        line-height: @title-size;
        color: white;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      > p {
        width: 100%;
        font-size: @normal-size;
        color: @node-color;
        word-break: break-all;
        line-height: @big-size;
        margin-top: 0.1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
  .content {
    width: 100%;
    display: flex;
    flex-direction: column;
    > div {
      display: flex;
      flex-direction: row;
      cursor: pointer;
      color: white;
      margin-bottom: 0.2rem;
      > i {
        width: 0.3rem;
        height: 0.3rem;
        border: 2px @gold-color solid;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: @normal-size;
        transition: all 300ms;
        color: @gold-color;
        margin-left: 1.2rem;
        border-radius: 50%;
        box-sizing: border-box;
      }
      > img {
        width: 0.3rem;
        height: 0.3rem;
        // border: 2px @gold-color solid;
        object-fit: contain;
        margin-left: 1.2rem;
        // border-radius: 50%;
        box-sizing: border-box;
      }
      > p {
        font-size: @title-size;
        color: @node-color;
        display: flex;
        align-items: center;
        margin-left: 0.1rem;
      }
    }
  }
}
.nav {
  width: @article-width;
  height: 0.8rem;
  background: white;
  color: @black-color;
  box-sizing: border-box;
  border-bottom: 1px @node-color solid;
  font-size: @big-size;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-evenly;
  > div {
    height: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  > div:hover {
    background: rgba(0, 0, 0, 0.1);
  }
  > div + div {
    border-left: 1px @node-color solid;
  }
}
</style>
